// src/utils/request.js
import axios from 'axios'

const request = axios.create({
  baseURL: 'http://localhost:8080', // 请根据后端端口确认
  timeout: 5000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 请求拦截器：添加 token
request.interceptors.request.use(config => {
  const token = sessionStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, error => {
  return Promise.reject(error)
})

// 响应拦截器：只返回 data
request.interceptors.response.use(
  response => response.data,
  error => Promise.reject(error)
)

export default request
